# -*- coding: utf-8 -*-
from django import forms
from main.models import Unit, Employee
from repairs.widgets import CalendarWidget


class SearchForm(forms.Form):
    lastname =  forms.CharField(label=u"Фамилия", max_length = 200, required=False)
    name = forms.CharField(label=u"Имя", max_length = 200, required=False)
    patronymic = forms.CharField(label=u"Отчество", max_length = 200, required=False)
    unit = forms.ModelChoiceField(label=u'Подразделение', queryset=Unit.objects.all(), required=False)
    in_dismissed = forms.BooleanField(label=u'Искать в уволенных?', required=False)
    in_repair = forms.BooleanField(label=u'Искать ремонтника?', required=False)

class E_CreateForm(forms.ModelForm):
    class Meta:
        model = Employee

    def __init__(self, *args, **kwargs):
        super(E_CreateForm, self).__init__(*args, **kwargs)
        self.fields['birthday'].widget = CalendarWidget()

    def clean(self):
        cleaned_data = self.cleaned_data
        profession = cleaned_data.get("profession")
        if not profession:
            raise forms.ValidationError("Поле профессия обязательное.")
        return cleaned_data